//
//  SettingViewController.m
//  ChatApp
//
//  Created by DJL on 15/12/21.
//  Copyright © 2015年 DJL. All rights reserved.
//

#import "SettingViewController.h"
#import "EaseMob.h"
#import "AppDelegate.h"
#import "ViewController.h"
#import "Masonry.h"
#define kTableViewCell @"cell"
@interface SettingViewController ()<IChatManagerDelegate,UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UISwitch *settingSwitch;

@end

@implementation SettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [[EaseMob sharedInstance].chatManager addDelegate:self delegateQueue:nil];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.title = @"设置";
    [self createTableView];
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50.f;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}

-(void)createTableView{
    
    self.tableView = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    self.tableView.separatorColor = [UIColor orangeColor];
    [self.view addSubview:self.tableView];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kTableViewCell];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
//        [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
//    
//            make.top.mas_equalTo(64);
//            make.right.mas_equalTo(0);
//            make.left.mas_equalTo(0);
//            make.bottom.mas_equalTo(-49);
//        }];
    
}



-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableViewCell];
    self.settingSwitch = [[UISwitch alloc]initWithFrame:CGRectMake(310, 10, 30, 30)];
    if (indexPath.row == 0 || indexPath.row == 4 || indexPath.row == 5 || indexPath.row == 7) {
        [cell.contentView addSubview:self.settingSwitch];
        
    } else{
        
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
    }
    cell.detailTextLabel.textAlignment = NSTextAlignmentRight;
    //    cell.backgroundColor = [UIColor blueColor];
    NSArray *arr = @[@"自动登录",@"消息推送设置",@"黑名单",@"诊断",@"使用IP",@"退群时删除会话",@"iOS离线推送昵称",@"显示视频通话信息",@"个人信息",@"设置视频通话码率"];
    cell.textLabel.text = [arr objectAtIndex:indexPath.row];
    cell.textLabel.font = [UIFont boldSystemFontOfSize:19];
    
    return cell;
    
}

//退出登录
- (IBAction)exitAction:(id)sender {
    
    [[EaseMob sharedInstance].chatManager asyncLogoffWithUnbindDeviceToken:YES  completion:^(NSDictionary *info, EMError *error) {
        if (!error && info) {
            NSLog(@"退出成功");
        }
    } onQueue:nil];
    // 退出，传入YES，会解除device token绑定，不再收到群消息；传NO，不解除device token
    [[EaseMob sharedInstance].chatManager asyncLogoffWithUnbindDeviceToken:NO];
    

}
//退出登录方法
- (void)didLogoffWithError:(EMError *)error {
    NSLog(@"sadgdasgadfas");
    
    
    AppDelegate *app = [UIApplication sharedApplication].delegate;
    
    
    UIStoryboard *stroy = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
    ViewController *viwe = [stroy instantiateViewControllerWithIdentifier:@"VC"];
    
    app.window.rootViewController = viwe;
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
